package com.tvsinfo.jdk.demo.case2_function_interface;


import com.tvsinfo.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class ConsumerDemo {

    public static void main(String[] args) {

        List<ArtemisInfo> artemisInfos = Arrays.asList(new ArtemisInfo("1", "22"), new ArtemisInfo("2", "22"), new ArtemisInfo(null, null));

        //实战
        artemisInfos.forEach(artemisInfo -> {
            method(artemisInfo, o -> artemisInfo.getKey().equals("1"), artemisInfo1 -> artemisInfo.setContent("222222222"));
            method(artemisInfo, o -> artemisInfo.getKey().equals("2"), artemisInfo1 -> artemisInfo.setContent("222222222"));
            method(artemisInfo, o -> StringUtils.isEmpty(artemisInfo.getKey()), ConsumerDemo::tTest);
        });

        //
        artemisInfos.forEach(System.out::print);
    }


    public static void tTest(ArtemisInfo artemisInfo) {
        System.out.println("deal ArtemisInfo " + artemisInfo.toString());
        artemisInfo.setKey("3");
        artemisInfo.setContent("3333333");
        //todo 其他各种逻辑

    }


    public static void method(ArtemisInfo artemisInfo, Predicate practice, Consumer<ArtemisInfo> artemisInfoConsumer) {
        if (practice.test(artemisInfo)) {
            artemisInfoConsumer.accept(artemisInfo);
        }
    }


    public static class ArtemisInfo {
        private String key;
        private String content;

        public ArtemisInfo(String key, String content) {
            this.key = key;
            this.content = content;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        @Override
        public String toString() {
            return "ArtemisInfo{" +
                    "key='" + key + '\'' +
                    ", content='" + content + '\'' +
                    '}' + "\n\r";
        }
    }

}
